home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1856 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. Path: news.th-darmstadt.de!news!enno
  2. From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Destructors in functions
  5. Date: 13 Jan 1996 13:37:57 GMT
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Distribution: world
  8. Message-ID: <ENNO.96Jan13143757@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  9. References: <4d7r65$dv9@newsbf02.news.aol.com>
  10. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  11. In-reply-to: weatby@aol.com's message of 13 Jan 1996 03:40:37 -0500
  12.  
  13. In article <4d7r65$dv9@newsbf02.news.aol.com> weatby@aol.com (Weatby) writes:
  14.  
  15.    If you pass an object to a function, the language makes a bitwise copy of
  16.    it, local to the function.  (Assuming no copy constructor is defined.) 
  17.    Then, on the way out, the function calls the user-defined constructor.
  18.  
  19.    This will cause problems if the object has any pointers in it (if they are
  20.    released by the destructor, as they 'should' be).
  21.  
  22.    The question is, why call a destructor on an object for which no
  23.    constructor was called?  The compiler has probably put the local copy on
  24.    its stack, and could pop it off on the way out.
  25.  
  26.    Calling a destructor, automatically, for which no constructor was called
  27.    seems to be a non-useful feature.  Does anyone know why this was included
  28.    in the language definition?
  29.  
  30. The default copy-ctor provided by the compiler does memberwise _not_ bitwise
  31. copy of the data-members. That could be the same, if e.g. all data-members
  32. are builtin types, but usually there is a difference.
  33. So it's reasonable to call the dtor in general when the copied instance goes
  34. out of scope. Anyway I don't think the standard _forbids_ optimization for
  35. trivial dtors.
  36.  
  37.         Enno
  38.